package com.example.smarthomeyzy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

import com.example.smarthomeyzy.R;

public class DemoActivity extends AppCompatActivity {
    RadioButton radioBUtton1;
    RadioButton radioBUtton2;
    RadioGroup group;
    public AppCompatTextView GO;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);

        GO =findViewById(R.id.GO);
        GO.setOnClickListener(view -> {
            Intent intent = new Intent(DemoActivity.this, SmartActivity.class);
            startActivityForResult(intent, 1);
        });
        initView();
//给按钮组添加 点击事件
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch(i)
                {
                    case R.id.radioBUtton1:
                        Toast.makeText(DemoActivity.this,"你选择了："+radioBUtton1.getText(),Toast.LENGTH_SHORT).show();
                        break;
                        case R.id.radioBUtton2:
                            Toast.makeText(DemoActivity.this,"你选择了："+radioBUtton2.getText(),Toast.LENGTH_SHORT).show();
                            break;
                }
            }
        });
    }
    private void initView() {
        group = findViewById(R.id.radiogroup);
        radioBUtton1 = findViewById(R.id.radioBUtton1);
        radioBUtton2 = findViewById(R.id.radioBUtton2);
    }
}
